<include file="Layout/header" />
<body>
<div class="breadcrumbs" id="breadcrumbs"> 
  <script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
  <ul class="breadcrumb">
    <li> <i class="icon-home home-icon"></i> <a href="{:U('Admin/Index/welcome')}">首页</a> </li>
    <li class="active">会员等级</li>
  </ul>
</div>
<div class="page-content">
  <div class="page-header">
    <h1> 会员管理 <small> <i class="icon-double-angle-right"></i> 会员等级 </small> </h1>
  </div>
  <div class="row">
     
    <div class="col-xs-12">
    <a class="btn btn-primary" style="margin-bottom: 5px;" href="#" onClick="add()"><i class="icon-plus align-top bigger-125"></i>新增等级</a>
      <div class="table-responsive">
        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
          <thead>
            <tr>
              <th class="center"> <label>
                  <input class="ace" type="checkbox">
                  <span class="lbl"></span> </label>
              </th>
              <th>ID</th>
              <th>等级名称</th>
              <th class="hidden-480">充值额度</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
          <form method="post" action="{:U('Admin/Member/rankdel')}" id="ondel">
            <foreach name="rank.data" item="val">
              <tr class="selected">
                <td class="center"><label>
                    <input class="ace" type="checkbox" value="{$val.rank_id}" name="rank_id[]">
                    <span class="lbl"></span> </label></td>
                <td>{$val.rank_id}</td>
                <td>{$val.rank_name}</td>
                <td class="hidden-480">{$val.money}</td>
                <td><div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
                    <a class="btn btn-xs btn-info" href="#" rankId="{$val['rank_id']}" rankName="{$val['rank_name']}" rankMoney="{$val['money']}"  onclick="edit(this)"> <i class="icon-edit bigger-120"></i> </a>
                    <if condition="$val.rank_id neq 1">
                     <a class="btn btn-xs btn-danger" onClick="rank_del(this,{$val.rank_id})"> <i class="icon-trash bigger-120"></i> </a> </div></td>
                   </if>
              </tr>
            </foreach>
          </form>
            </tbody>
          
        </table>
        <div>
          <button class="btn btn-danger" onClick="datadel()">批量删除</button>
        </div>
      </div>
      
      <!-- /.table-responsive --> 
    </div>
    <div >{$member.page}</div>
  </div>
</div>

<div class="modal fade" id="nav-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
        <h4 class="modal-title" id="myModalLabel"> 添加等级</h4>
      </div>
      <div class="modal-body">
        <form id="bjy-form" class="form-inline" action="{:U('Admin/Member/rank_add')}" method="post">
          <table class="table table-striped table-bordered table-hover table-condensed">
            <tr>
              <th width="15%">等级名称：</th>
              <td><input class="form-control" type="text" name="rank_name"></td>
            </tr>
            <tr>
              <th>充值额度：</th>
              <td><input class="form-control" type="text" name="money">
                填写金额不要于其他等级金额相同</td>
            </tr>
            <tr>
              <th></th>
              <td><input class="btn btn-success" type="submit" value="添加"></td>
            </tr>
          </table>
        </form>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
        <h4 class="modal-title" id="myModalLabel"> 修改等级</h4>
      </div>
      <div class="modal-body">
        <form id="bjy-form" class="form-inline" action="{:U('Admin/Member/rank_edit')}" method="post">
          <input type="hidden" name="rank_id">
          <table class="table table-striped table-bordered table-hover table-condensed">
            <tr>
              <th width="15%">等级名称：</th>
              <td><input class="form-control" type="text" name="rank_name"></td>
            </tr>
            <tr>
              <th>充值额度：</th>
              <td><input class="form-control" type="text" name="money">
                填写金额不要于其他等级金额相同</td>
            </tr>
            <tr>
              <th></th>
              <td><input class="btn btn-success" type="submit" value="修改"></td>
            </tr>
          </table>
        </form>
      </div>
    </div>
  </div>
  <input type="hidden" value="{:U('Admin/Member/rank_del')}" id="rank_del">
</div> 
<include file="Layout/js"/> 
<link href="__ADMIN_CSS__/datepicker.css" rel="stylesheet" />
<script src="__ADMIN_JS__/date-time/bootstrap-datepicker.min.js"></script>
<script src="__ADMIN_JS__/jquery.ui.touch-punch.min.js"></script>
<script src="__ADMIN_JS__/jquery.dataTables.min.js"></script> 
<script src="__ADMIN_JS__/jquery.dataTables.bootstrap.js"></script> 
<script src="__ADMIN_JS__/bootbox.js"></script> 
<script type="text/javascript">
			jQuery(function($) {
 				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
			
  				
			})
 		</script> 
<script type="text/javascript">       
 
     /*删除*/
function rank_del(obj,id){
	var host=$("#rank_del").val();
      bootbox.setLocale("zh_CN");  
      bootbox.confirm("确定删除该等级?", function(result) {  
        if (result) {  
           $.ajax({
        			url:host,
        			type:"POST",
        			dataType:"json",
        			data:{rank_id:id},
        			success: function(s){
         				if(s.status == '1'){
        				$(obj).parents("tr").remove();
        				bootbox.alert('删除成功');
        				}else{
        				bootbox.alert(s.info);	
        					}
        				}
			     })		 
        }  
      });  
 
}
/*批量-删除*/
function datadel(){
	 var is_check=$("input[type='checkbox']").is(':checked');
   if(is_check){
      bootbox.setLocale("zh_CN");  
      bootbox.confirm("确定删除该等级?", function(result) {  
        if (result) {  
           $("#ondel").submit();
         }  
      });
   }else{
     bootbox.alert({  
            buttons: {  
               ok: {  
                    label: '返回',  
                    className: 'btn-myStyle'  
                }  
            },  
            message: '请选择要删除的等级',  
            callback: function() {  
               // alert('关闭了alert');  
            },  
            title: "提示信息",  
        });
   }	
}
// 添加
function add(){
  $("input[name='rank_name'],input[name='money']").val('');
  $('#nav-add').modal('show');
}
// 修改
function edit(obj){
  var rankId=$(obj).attr('rankId');
  var rankName=$(obj).attr('rankName');
  var rankMoney=$(obj).attr('rankMoney');

   $("input[name='rank_id']").val(rankId);
   $("input[name='rank_name']").val(rankName);
   $("input[name='money']").val(rankMoney);
   $('#bjy-edit').modal('show');
}
 </script>
</body>
</html>